import os

import nltk

# 设置国内镜像，因Image处理需下载nltk数据
os.environ['NLTK_DATA_URL'] = 'https://mirrors.tuna.tsinghua.edu.cn/nltk_data/'


def nltk_download():
    print('start to download nltk')

    nltk.download(
        'averaged_perceptron_tagger_eng',
        force=True,  # 强制重新下载
    )

    nltk.download(
        'punkt_tab',
        force=True,  # 强制重新下载
    )

    print("nltk download complete")


# 下载huggingface模型，设置代理
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'  # 国内可用

from langchain_community.document_loaders.image import UnstructuredImageLoader


def parse_png():
    loader = UnstructuredImageLoader("data/pycharm.png", mode="single")  # 保留段落
    docs = loader.load()
    for doc in docs:
        print(doc.page_content)  # OCR 后的文本
        print(doc.metadata)  # 坐标、类型、页码等


if __name__ == '__main__':
    parse_png()
    # nltk_download()
